package com.amit.hibernate;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Client3 {

	public static void main(String[] args) {
		
		SessionFactory sessionfactory=ChibernateUtil.getfactory();
		Session session=sessionfactory.openSession();
		Transaction tx=session.beginTransaction();
		
		Customer cust=(Customer)session.load(Customer.class, 1);
		Book b1=(Book) session.load(Book.class, 1);
		OrderItem oi1=new OrderItem(1, 100);
		oi1.setBook(b1);
		session.save(oi1);
		
		Book b2=(Book) session.load(Book.class, 2);
		OrderItem oi2=new OrderItem(2, 100);
		oi2.setBook(b2);
		session.save(oi2);
		
		ShippingAddress add=new ShippingAddress("AMP","HYD","AP");
		session.save(add);
		
		Set<OrderItem> orderItems=new HashSet<OrderItem>();
		orderItems.add(oi1);
		orderItems.add(oi2);
		
		Order order=new Order(3, 300.0, new Date(), "NEW");
		order.setAddress(add);
		order.setOrderItems(orderItems);
		order.setCustomer(cust);
		session.save(order);
		
		
		
		
		tx.commit();
		session.close();

	}

}
